<script setup>
import { ref, watch, onMounted } from 'vue'
import { useRouter, useRoute } from 'vue-router'

const router = useRouter()
const route = useRoute()
const activeTab = ref(route.path === '/calculator' ? 'calculator' : 'batch')

watch(() => route.path, (newPath) => {
  activeTab.value = newPath === '/calculator' ? 'calculator' : 'batch'
}, { immediate: true })

onMounted(() => {
  activeTab.value = route.path === '/calculator' ? 'calculator' : 'batch'
  console.log('当前路由:', route.path, '激活的选项卡:', activeTab.value)
})

const handleTabChange = (tab) => {
  console.log('切换到选项卡:', tab)
  
  if (tab !== activeTab.value) {
    if (tab === 'calculator') {
      router.push('/calculator')
    } else if (tab === 'batch') {
      router.push('/')
    }
  }
}
</script>

<template>
  <div class="app-container">
    <div class="app-header">
      <div class="app-tabs">
        <div 
          class="tab-item" 
          :class="{ active: activeTab === 'batch' }"
          @click="handleTabChange('batch')"
        >
          <i class="el-icon-folder-opened"></i>
          <span>批量处理</span>
        </div>
        <div 
          class="tab-item" 
          :class="{ active: activeTab === 'calculator' }"
          @click="handleTabChange('calculator')"
        >
          <i class="el-icon-data-analysis"></i>
          <span>单条处理</span>
        </div>
      </div>
    </div>
    <div class="app-content">
  <router-view />
    </div>
  </div>
</template>

<style>
html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  width: 100%;
  overflow: hidden;
}

#app {
  margin: 0;
  padding: 0;
  height: 100%;
  width: 100%;
  overflow: hidden;
}

* {
  box-sizing: border-box;
}

.app-container {
  display: flex;
  flex-direction: column;
  height: 100%;
  width: 100%;
  font-family: 'Inter', 'Segoe UI', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', sans-serif;
}

.app-header {
  background: linear-gradient(135deg, #4a6cf7 0%, #2b3cf5 100%);
  padding: 0;
  z-index: 10;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
}

.app-tabs {
  display: flex;
  padding: 0 30px;
}

.tab-item {
  padding: 18px 24px;
  color: rgba(255, 255, 255, 0.85);
  cursor: pointer;
  display: flex;
  align-items: center;
  transition: all 0.3s;
  border-bottom: 3px solid transparent;
  font-weight: 500;
  letter-spacing: 0.3px;
}

.tab-item:hover {
  color: #fff;
  background-color: rgba(255, 255, 255, 0.15);
}

.tab-item.active {
  color: #fff;
  border-bottom: 3px solid #fff;
  font-weight: 600;
  background-color: rgba(255, 255, 255, 0.1);
}

.tab-item i {
  margin-right: 10px;
  font-size: 18px;
}

.app-content {
  flex: 1;
  overflow: hidden;
  position: relative;
  background-color: #f8f9fa;
  padding: 20px;
}
</style>
